#include <stdio.h>
#include <math.h>
#define E 0.5*1e-5
int main()
{
	double f(double x);
	double a, b, c;
	int num;
	a = 1, c = 2, num = 0;
	do {
		b = (a + b) / 2;
		num++;
		if (f(a)*f(c) < 0)
			b = c;
		else if (f(a)*f(c) > 0)
			a = c;
		else
			break;
	} while ((b - a) > E);
	c = (a + b) / 2;
	printf("The root is %lf.\n", c);
	printf("The number of iterations is %d.\n", num);
	return 0;
}

double f(double x)
{
	return sin(x) - pow(x, 2) / 2;
}
